﻿using System;
using System.Collections.Generic;
using Ext.Net;
using BLL;
using Model;
using System.Xml;
using System.Xml.Xsl;

namespace Web.View.d1011Menu
{
    public partial class Default : UIPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        //绑定Grid
        protected void d1011_DataBind(object sender, StoreRefreshDataEventArgs e)
        {
            d1011Mgr mgr = new d1011Mgr();
            e.Total = int.Parse(mgr.GetRecordCount_d1011(e.Parameters[d1011_Filter.ParamPrefix]));
            IList<d1011> list = mgr.FindAllByPage_d1011(e.Start.ToString(), e.Limit.ToString(), e.Parameters[d1011_Filter.ParamPrefix]);
            d1011_MainStore.DataSource = list;
            d1011_MainStore.DataBind();
        }
        //删除数据
        protected void BtnDel_Click(object sender, DirectEventArgs e)
        {
            d1011Mgr mgr = new d1011Mgr();
            RowSelectionModel sm = d1011_Grid.SelectionModel.Primary as RowSelectionModel;
            foreach (SelectedRow row in sm.SelectedRows)
            {
                d1011 _d1011 = new d1011();
                _d1011.jgdm = row.RecordID;//int.Parse(row.RecordID);
                if (mgr.Del_d1011(_d1011))
                {
                    log.Debug("d1011中执行了删除，并成功");
                    X.Msg.Notify("成功", "<font color='green'>已经成功删除选中的记录</font>").Show();
                }
                else
                    X.Msg.Notify("失败", "<font color='green'>删除记录失败，请您重试！</font>").Show();
            }
            d1011_Grid.Reload();
        }
        protected void BtnSave_Click(object sender, DirectEventArgs e)
        {
            d1011Mgr mgr = new d1011Mgr();
            d1011 _d1011 = new d1011();
            if (Hid.Text.Length > 0)
                _d1011 = mgr.FindById_d1011(int.Parse(Hid.Text));
            
			_d1011.jgmc = Txtjgmc.Text.Trim();
			_d1011.zjdm = Txtzjdm.Text.Trim();
			_d1011.dsgx = Txtdsgx.Text.Trim();
			_d1011.zpdw = Txtzpdw.Text.Trim();
			_d1011.jjlx = Txtjjlx.Text.Trim();
			_d1011.jglb = Txtjglb.Text.Trim();
			_d1011.jgjb = Txtjgjb.Text.Trim();
			_d1011.shyl = Txtshyl.Text.Trim();
			_d1011.tsdz = Txttsdz.Text.Trim();
			_d1011.yzbm = Txtyzbm.Text.Trim();
			_d1011.dhhm = Txtdhhm.Text.Trim();
			_d1011.dzyx = Txtdzyx.Text.Trim();
			_d1011.clsj = Txtclsj.Text.Trim();
			_d1011.hddb = Txthddb.Text.Trim();
			_d1011.zzzj = Txtzzzj.Text.Trim();
			_d1011.wsgs = Txtwsgs.Text.Trim();
			_d1011.ycws = Txtycws.Text.Trim();
			_d1011.scws = Txtscws.Text.Trim();
			_d1011.rs = Txtrs.Text.Trim();
			_d1011.wjrs = Txtwjrs.Text.Trim();
			_d1011.kssl = Txtkssl.Text.Trim();
			_d1011.ssdq = Txtssdq.Text.Trim();
			_d1011.mzrs = Txtmzrs.Text.Trim();
			_d1011.chmzs = Txtchmzs.Text.Trim();
			_d1011.ncys = Txtncys.Text.Trim();
			_d1011.chcys = Txtchcys.Text.Trim();
			_d1011.nsr = Txtnsr.Text.Trim();
			_d1011.chnsr = Txtchnsr.Text.Trim();
			_d1011.sblx = Txtsblx.Text.Trim();
			_d1011.pzlx = Txtpzlx.Text.Trim();
			_d1011.pybm = Txtpybm.Text.Trim();
			_d1011.wbbm = Txtwbbm.Text.Trim();
			_d1011.qtbm = Txtqtbm.Text.Trim();

            bool isok = false;
            if (Hid.Text.Length > 0)
                isok = mgr.Update_d1011(_d1011);
            else
                isok = mgr.Add_d1011(_d1011);
            if (isok)
            {
                d1011_Win.Hide();
                X.Msg.Notify("成功", "<font color='green'>恭喜您，操作成功！</font>").Show();
                log.Debug("d1011中执行了保存（插入或修改），并成功");
                d1011_Grid.Reload();
            }
            else
                X.Msg.Notify("失败", "<font color='red'>操作失败，请您重试！</font>").Show();
        }
        //数据保存为Excel
        protected void BtnSaveToExcel(object sender, EventArgs e)
        {
            string json = ExcelGridData.Value.ToString();
            StoreSubmitDataEventArgs eSubmit = new StoreSubmitDataEventArgs(json, null);
            XmlNode xml = eSubmit.Xml;
            this.Response.Clear();
            this.Response.ContentType = "application/vnd.ms-excel";
            this.Response.AddHeader("Content-Disposition", "attachment; filename=QiDian10Excel.xls");
            XslCompiledTransform xtExcel = new XslCompiledTransform();
            xtExcel.Load(Server.MapPath("/View/ExcelTemp/Excel.xsl"));
            xtExcel.Transform(xml, null, this.Response.OutputStream);
            this.Response.End();

        }
    }
}